<?php
namespace Wap\Controller;
use Wap\Controller\CommonController;
class OrdersController extends CommonController {

   public function index(){
   if (IS_POST) {
       $ids=I('post.id');
       foreach ($ids as $key => $value) {
         foreach ($_SESSION['goods'] as $key => $v) {
          if ($value==$v['id']) {
                  $m=M('user')->where('id='.$v['userid'])->find();
                      $v['user']=$m['user'];
                       $v['baojia']=$m['baojia'];
                        $v['chengshi']=$m['chengshi'];
                   $arr[]=$v;

          }
         }
       }


       
    
$this->assign('goods',$arr);

   }else{
       

         $id=I('get.id');

         $goods=M('shangpin')->alias('a')->field('a.id,a.name, a.userid,a.fengge,a.huxing,a.area,a.price,a.img,b.user,b.baojia,b.chengshi')->join('zyb_user b on b.id=a.userid')->where('a.id='.$id)->select();
           // $_SESSION['url']=__SELF__;
           $this->assign('goods',$goods);
}
     
     $dizhi=M('address')->where('dzid='.$_SESSION['userid'])->select();

$this->assign('dizhi',$dizhi);

   	$this->display();
   }
    
    public function dingdan(){ 

$model=M('dingdan');
 $data['code']=time().rand(10000,99999);
  $data['time']=time();
for ($i=0; $i < count($_POST['goodid']); $i++) { 


 $data['gid']=$_POST['goodid'][$i];
  $data['aid']=$_POST['aid'];
  $data['sjid']=$_POST['sjid'][$i];
  $data['uid']=$_SESSION['userid'];
   $data['zid']=1;
   $data['fid']=1;
   $model->add($data);
   }

 for ($i=0; $i < count($_POST['goodid']); $i++) { 
   unset($_SESSION['goods'][$_POST['goodid'][$i]]);
 }
  	$this->redirect('User/person',array('zid'=>1));  


  


}


    



}

?>